package com.base.cn.platform.os.controller.mobile.classes.personal;


import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.service.course.classes.topic.ClassesTopicService;
import com.base.cn.platform.os.service.manage.user.user.CusUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * H5个人班级话题详情Controller
 *
 * @author zsw
 * @create 2018/7/5
 */
@Controller
@RequestMapping("")
public class MobilePersonalClassTopicController extends MobileBaseController {

    @Autowired
    private ClassesTopicService classesTopicService;
    @Autowired
    private CusUserService cusUserService;

    /**
     * 我的话题页面
     * @return
     */
    @RequestMapping("/mobile/uc/topic/myTopic")
    public String toMyTopic() {
        return resultPage("/class/personal/my-topic-index");
    }

    /**
     * 我的话题列表
     * @param currentPage
     * @param which 1.全部 2.发表的 3.回复的 4 分享的
     * @return
     */
    @RequestMapping("/mobile/uc/ajax/list/myTopic")
    public String listMyTopic(HttpServletRequest request,
                              Model model,
                              @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage,
                              @RequestBody  Map<String, Object> which) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String, Object> userInfo = cusUserService.userInfo(userId, false, false, false, false, false, false, false);
        model.addAttribute("user",userInfo);
        Integer _which = (Integer)which.get("which");
        Map<String, Object> classesPersonalTopicPage = classesTopicService.findClassesPersonalTopicPage(userId, currentPage, null, _which, true, false, false);
        model.addAttribute("dataMap", classesPersonalTopicPage);
        return resultPage("/class/personal/ajax-list-topic-personal");
    }

    /**
     * 我的动态
     */
    @RequestMapping("/mobile/uc/topic/personal/index")
    public String toTopicPersonal() {
        return resultPage("/class/personal/topic-personal");
    }

    /**
     * 用户加入的班级内的所有话题
     */
    @RequestMapping("/mobile/uc/topic/personal/ajax/list/topic")
    public String listPersonalTopic(Model model,
                                    HttpServletRequest request,
                                    @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String, Object> classesPersonalTopicPage = classesTopicService.findClassesPersonalTopicPage(userId, currentPage, 10, 1, true, false, false);
        model.addAttribute("dataMap",classesPersonalTopicPage);
        return resultPage("/class/topic/ajax-list-topic");
    }

}
